package com.jelly.concurrency.thread;

public class Selfmanaged implements Runnable{
	
	private int countDwon=5;
	
	private Thread t = new Thread(this);
	
	public Selfmanaged(){
		t.start();
	}
	
	@Override
	public String toString() {
		return Thread.currentThread().getName()+"("+countDwon+"),";
	}
	
	@Override
	public void run() {
		while(true){
			System.out.println(this);
			if(--countDwon==0){
				return;
			}
		}
	}
	
	public static void main(String[] args) {
		for (int i = 0; i < 5; i++) {
			new Selfmanaged();
		}
	}

}
